﻿<Controls:MetroWindow xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                      xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                      xmlns:converters="clr-namespace:WPFEntityValidation.Converters"
                      xmlns:Utilities="clr-namespace:WPFEntityValidation.Utilities"
                      mc:Ignorable="d"
                      x:Class="WPFEntityValidation.MainWindow"
                      Title="Entity Validation With WPF MVVM"
                      Height="400"
                      Width="500"
                      WindowStartupLocation="CenterScreen"
                      ShowTitleBar="True"
                      ShowIconOnTitleBar="true"
                      x:Name="window">
    <AdornerDecorator>
        <Grid>
            <Grid.Resources>
                <converters:NullObjectToBoolConverter x:Key="NullObjectToBoolConverter" />
            </Grid.Resources>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="5" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="25" />
                <RowDefinition Height="Auto" />

            </Grid.RowDefinitions>

            <TextBlock Margin="10" Text="Person Details" FontFamily="{StaticResource HeaderFontFamily}"
                       FontSize="{StaticResource HeaderFontSize}" />

            <Grid Margin="20,10,0,0" Grid.Row="2" DataContext="{Binding Person}">

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="5" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="5" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="5" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="5" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="5" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <TextBlock Text="First Name" VerticalAlignment="Center" />
                <TextBox
                    Utilities:AttachedProperties.ValidateEntity="{Binding ElementName=window, Path=DataContext.Person}"
                    Utilities:AttachedProperties.ValidateFieldName="First Name"
                    Grid.Column="2"
                    Text="{Binding FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                    Controls:TextboxHelper.Watermark="Enter First Name"
                    Controls:TextboxHelper.ClearTextButton="True"
                    VerticalAlignment="Top"
                    HorizontalAlignment="Left"
                    Width="154.002"
                    VerticalContentAlignment="Center" />

                <TextBlock Grid.Row="2" Text="Middle Name" VerticalAlignment="Center" />
                <TextBox
                    Grid.Row="2"
                    Grid.Column="2"
                    Text="{Binding MiddleName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Left"
                    Width="40"
                    VerticalContentAlignment="Center" />

                <TextBlock Grid.Row="4" Text="Last Name" VerticalAlignment="Center" />
                <TextBox Grid.Row="4"
                         Grid.Column="2"
                         Utilities:AttachedProperties.ValidateEntity="{Binding ElementName=window, Path=DataContext.Person}"
                         Utilities:AttachedProperties.ValidateFieldName="Last Name"
                         Text="{Binding LastName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                         Controls:TextboxHelper.Watermark="Enter Last Name"
                         Controls:TextboxHelper.ClearTextButton="True"
                         VerticalAlignment="Top"
                         HorizontalAlignment="Left"
                         Width="154.002"
                         VerticalContentAlignment="Center" />

                <TextBlock Grid.Row="6" Text="Age" VerticalAlignment="Center" />
                <TextBox Grid.Row="6"
                         Grid.Column="2"
                         Text="{Binding Age}"
                         VerticalAlignment="Top"
                         HorizontalAlignment="Left"
                         Width="80"
                         Utilities:AttachedProperties.ValidateEntity="{Binding ElementName=window, Path=DataContext.Person}"
                         Utilities:AttachedProperties.ValidateFieldName="Age"
                         VerticalContentAlignment="Center" />

                <TextBlock Grid.Row="8" Text="Email" VerticalAlignment="Center" />
                <TextBox Grid.Row="8"
                         Grid.Column="2"
                         Utilities:AttachedProperties.ValidateEntity="{Binding ElementName=window, Path=DataContext.Person}"
                         Utilities:AttachedProperties.ValidateFieldName="Email"
                         Text="{Binding Email, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                         Controls:TextboxHelper.Watermark="Email : amar@amar.com"
                         Controls:TextboxHelper.ClearTextButton="True"
                         VerticalAlignment="Top"
                         HorizontalAlignment="Left"
                         Width="200"
                         VerticalContentAlignment="Center" />
            </Grid>

            <Grid Grid.Row="4" Visibility="Collapsed">
                <StackPanel Orientation="Horizontal">
                    <Button Content="Okay" Width="154.002" Height="30"
                            Command="{Binding ErrorCommand}" />
                    <Button Content="Cancel" Width="154.002" Height="30"
                            Command="{Binding ErrorCommand}" />
                </StackPanel>

            </Grid>

            <Popup Grid.RowSpan="5" StaysOpen="False"
                   IsOpen="{Binding ErrorList, Converter={StaticResource NullObjectToBoolConverter}}"
                   PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"
                   Placement="MousePoint">
                <Border x:Name="PopupBorder"
                        Effect="{DynamicResource DropShadowBrush}"
                        HorizontalAlignment="Stretch"
                        Height="Auto"
                        BorderBrush="{DynamicResource ComboBoxPopupBrush}"
                        Background="{DynamicResource WhiteBrush}">
                    <ScrollViewer x:Name="DropDownScrollViewer" BorderThickness="0" Margin="2" Padding="1">
                        <ItemsControl ItemsSource="{Binding ErrorList}" />
                    </ScrollViewer>
                </Border>
            </Popup>
        </Grid>
    </AdornerDecorator>
</Controls:MetroWindow>
